/*
write by wuweiwei(邬畏畏)
wui:www.flybirdsoft.com/WUI
blogs:www.cnblogs.com/wsoft
*/
(function(win){

	wEvent ={
		version:"1.0",
		cancelEvent : false
	};
	wEvent.on = function(options){
		/*
		options.rootElement
		options.queryString = "li div.abc"
		options.type
		options.process
		*/
		var i;
		this.options = options;
		this.queryAr = this.options.queryString!=undefined ? this.options.queryString.split(" ") : [];
		this.queryArLen = this.queryAr.length;
		var th = this;
		this.options.rootElement.addEventListener(this.options.type,function(e){
			var target = e.target||e.srcElement;
			var object = {};
			var Elstr = "";
			var isExit = false;

			if(th.cancelEvent)
			{
				return;
			}
			for(i=th.queryArLen-1 ; i>=0 ; i--)
			{
				object[th.queryAr[i]] = target;
				console.log(th.queryAr[i]);
				Elstr = th.queryAr[i].toLowerCase();
				do
				{
					if(Elstr.indexOf(".")==0)
					{
						if(target.className.indexOf(Elstr.replace(".",""))>=0)
						{
							break;
						}
					}
					else if(Elstr.indexOf(".")>0)
					{
						if( Elstr.indexOf(target.nodeName.toLowerCase())>-1 && target.className.indexOf(Elstr.split(".")[1])>-1 )
						{
							break;
						}

					}
					else
					{
						if(target.nodeName.toLowerCase()==Elstr)
						{
							break;
						}
					}
					if(target==th.options.rootElement)
					{
						isExit = true;
						break;
					}
					target = target.parentNode;
					object[th.queryAr[i]] = target;
				}while(1);

				if(isExit)
				{
					break;
				}
			}/*end for*/

			if(i==-1 || options.queryString==undefined || (options.queryString!=undefined&&options.queryString==""))
			{
				th.targets = object;
				th.options.process.call(th,e);
			}

		},false);
	};

	window.wEvent = wEvent;
})(window);

/*
调用示例

wEvent.on({
	rootElement:document.getElementById("viewList"),
	type:"click",
	queryString:"li .light",       //指定rootElement里的 "li .light" 元素的事件响应
	process:function(e){
		alert("你单击了 li元素里class=“light” 的元素");
		alert("被触发的DOM:"+this.targets[".light"]);
		alert("被触发的DOM:"+this.targets["li"]);

		//this.cancelEvent = true;  //取消事件处理
	}
});


*/
